<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title留言管理 - Layui</title>
<link rel="stylesheet" href="/layui/css/layui.css">
<link rel="stylesheet" href="/css/admin.css">
<link rel="stylesheet" href="/css/mypage.css">
</head>
<body>
<div class="layui-layout layui-layout-admin">
  <div class="layui-header">
    <!-- 头部区域（可配合layui已有的水平导航） -->
      @include('admin.header')
  </div>
  <div class="layui-side layui-bg-black">
      @include('admin.left')
  </div>
  <div class="layui-body">
  <form action="index" method="post">
  <div class="layui-form-item" ">
        <label class="layui-form-label">关键字</label>
        <div class="layui-input-inline">
          <input type="text" name="s" lay-verify="required" value="" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux" style="margin-top: -5px"> <button class="layui-btn layui-btn-small layui-btn-normal" sytle="">GO</button></div>
    </div>   
    <table class="table table-hover" id="list"> 
      <tr>
          <th width="145">选择</th>
          <th width="45">ID</th>                       
          <th width="550">内容</th>
          <th width="100">留言者</th>
          <th width="250">标题</th>
        
          <th width="200">发布时间</th>
          <th width="200">审核状态</th>
          <th width="220">操作</th>
      </tr>
      
      <?php foreach($messages->results as $val=>$v):?>           
        <tr>
          <td><input type="checkbox"  value="<?php echo $v['id']; ?>"  /></td>
          <td><?php echo $v["id"];?></td>                      
          <td><?php 
          $con=strip_tags($v["message"]);                        
           echo substr($con,0,60)."......";                     
          ?></td>
          <td><?php echo $v["username"];?></td>                     
          <td><?php echo $v["title"];?></td>
                             
          <td><?php echo date('Y-m-d H:i:s', $v['time']); ?></td>
          <td>
            <div class="layui-input-block" style="margin-left: -4px">
              <select name="interest" lay-filter="aihao" class="xuan">
             <?php if($v['flag']==1):?>
                <option value="1" selected>通过</option>
                <option value="0" >未通过</option>
             <?php endif;?>
             <?php if($v['flag']==0):?>
                <option value="1">通过</option>
                <option value="0" selected>未通过</option>
             <?php endif;?>
             </select>                        
            </div>
          </td>
          <td><a href="show?id=<?php echo $v['id'];?>">查看详情</a> <a class="button border-yellow button-little" href="dele?id=<?php echo $v['id'];?>" onclick="{
                      if (confirm('确认删除?')) {
                          return true;
                      }
                      return false;
                  }">删除</a></td>
        </tr>
       <?php endforeach;?>  
    </table>
    </form>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;"> </fieldset>
    <div id="page-v" style="margin-left: 50px"></div>     
  </div>
  <div class="layui-footer">
    <!-- 底部固定区域 -->
  </div>
</div>
<script src="/layui/layui.js"></script>
<script type="text/javascript" src="/js/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
    $(function(){
      $('.xuan').change(function(){
        var flag = $(this).val();
        var tr = $(this).parents('tr');
        var id = tr.find("td").eq(1).html();            
        $.ajax({
          url:"messageajax",
          type:'post',
          data:{'id':id,'flag':flag},
          dataType:'text',
          success:function(d){
            if(d==1){           
             // window.location.reload();
             alert('修改成功');
            }else{
              alert('修改失败');
            }
          }
        })
      })
    })

</script>
<script>
//JavaScript代码区域
layui.use('element', function(){
  var element = layui.element(); //导航的hover效果、二级菜单等功能，需要依赖element模块

});

layui.use(['laypage', 'layer'], function(){

  var total = <?php echo $messages->last; ?>;
  var laypage = layui.laypage
  ,layer = layui.layer;

  //好像很实用的样子，后端的同学再也不用写分页逻辑了。
  laypage({
    cont: 'page-v',
    pages: <?php echo $messages->last; ?>, //可以叫服务端把总页数放在某一个隐藏域，再获取。假设我们获取到的是18
    curr: function(){ //通过url获取当前页，也可以同上（pages）方式获取
      var page = location.search.match(/page=(\d+)/);
      return page ? page[1] : 1;
    }(), 
    jump: function(e, first){ //触发分页后的回调
      if(!first){ //一定要加此判断，否则初始时会无限刷新
        location.href = '?page='+e.curr+'&s=<?php echo $s?>';
      }
    }
  });


});


</script>
</body>
</html>